unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, AYTrayIcon, Menus, ActnList, StdCtrls;

type
  TFormMain = class(TForm)
    TimerYW: TTimer;
    TrayIconSvr: TAYTrayIcon;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N3: TMenuItem;
    ActionList1: TActionList;
    ActionClose: TAction;
    ActionMain: TAction;
    ActionHide: TAction;
    ActionShutDown: TAction;
    ButtonQXShutDown: TButton;
    ActionQXShutdown: TAction;
    procedure FormCreate(Sender: TObject);
    procedure TimerYWTimer(Sender: TObject);
    procedure ActionMainExecute(Sender: TObject);
    procedure ActionHideExecute(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ActionShutDownExecute(Sender: TObject);
    procedure ActionQXShutdownExecute(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure ButtonQXShutDownClick(Sender: TObject);
  private
    { Private declarations }
    FZXRQ,FZXSJ : Integer;
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.FormCreate(Sender: TObject);
begin
  With TrayIconSvr Do
  begin
    Hint := Self.Caption;
    Icon.Handle := Application.Icon.Handle;
    Active := True;
  end;

  FZXRQ := Trunc(Now);
  FZXSJ := 0;
end;

procedure TFormMain.TimerYWTimer(Sender: TObject);
var
  iRQ,iSJ,iH,iMM,iSS,iMS : Word;
begin
  iRQ := Trunc(Now);
  DecodeTime(Now,iH,iMM,iSS,iMS);
  iSJ := iH * 3600 + iMM * 60 + iSS;
  FZXSJ := 2 * 3600;
  
  TimerYW.Enabled := False;
  try
    if (iRQ>FZXRQ) and (iSJ>FZXSJ) then
    begin
      ActionMain.Execute;
      ActionShutDown.Execute;
    end;

  finally
    FZXRQ := iRQ;
    TimerYW.Enabled := True;
  end;

end;

procedure TFormMain.ActionMainExecute(Sender: TObject);
begin
  Self.WindowState := wsMaximized;
  Application.MainForm.Show;
end;

procedure TFormMain.ActionHideExecute(Sender: TObject);
begin
  FormMain.Hide;
  TimerYW.Enabled := True;
end;

procedure TFormMain.Button1Click(Sender: TObject);
begin
  ActionHide.Execute;
end;

procedure TFormMain.ActionShutDownExecute(Sender: TObject);
begin
  winexec('cmd.exe /c  shutdown -s -t 120 ',sw_hide);
end;

procedure TFormMain.ActionQXShutdownExecute(Sender: TObject);
begin
  winexec('cmd.exe /c  shutdown -a ',sw_hide);

end;

procedure TFormMain.FormResize(Sender: TObject);
begin
  ButtonQXShutDown.Left := (Self.Width - ButtonQXShutDown.Width) div 2;
//  ButtonQXShutDown.Top := Self.Height div 2;

end;

procedure TFormMain.ButtonQXShutDownClick(Sender: TObject);
begin
  ActionQXShutdown.Execute;
  ActionHide.Execute;
end;

end.
